<template>
  <div>
    <router-link to="/admin/addAdmin"><el-button>添加</el-button></router-link>
    <el-table
      :data="adminList"
      :stripe="true"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="username"
        label="用户名">
      </el-table-column>
      <el-table-column
        prop="password"
        label="密码">
      </el-table-column>

      <el-table-column
        label="状态">
        <template slot-scope="scope">
          <div v-if="scope.row.status==0">有效</div>
          <div v-if="scope.row.status==1">无效</div>
        </template>
      </el-table-column>

      <el-table-column
        label="操作">
        <template slot-scope="scope">
          <router-link to=""><el-button>修改</el-button></router-link>
          <el-button @click="deleteAdmin(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <router-view/>
  </div>
</template>

<script>
    export default {
        name: "AdminList",
      data(){
          return {
            adminList:[]
          }
      },
      created(){
        //发出ajax请求请求后端代码
        this.selectAll();
      },
      methods:{
        selectAll(){
          this.axios.get("/user/api/user/showAll").then((resp)=>{
            this.adminList=resp.data.data;
          });
        },
        deleteAdmin(id){
          this.$confirm("是否确认删除").then(()=>{
            this.axios.delete("/user/api/user/delete/"+id).then((resp)=>{
              if(resp.data.code==1){
                this.$message.success("删除成功");
                this.selectAll();
              }else{
                this.$message.success("删除失败");
              }
            });
          });
        }
      }
    }
</script>

<style scoped>

</style>
